/**
* 订单管理 交易订单
*/
<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>交易订单</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 搜索筛选 -->
    <el-form :inline="true" :model="formInline" class="user-search">
      <el-form-item label="搜索：">
        <el-input size="small" v-model="formInline.machineNo" placeholder="输入终端编号"></el-input>
      </el-form-item>
      <el-form-item>
        <el-input size="small" v-model="formInline.orderNo" placeholder="输入订单号"></el-input>
      </el-form-item>
      <el-form-item>
        <el-input size="small" v-model="formInline.transId" placeholder="输入交易单号"></el-input>
      </el-form-item>
      <el-form-item>
        <el-select size="small" v-model="formInline.orderStatus" placeholder="请选择">
          <el-option v-for="type in payway" :label="type.key" :value="type.value" :key="type.value"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button size="small" type="primary" icon="el-icon-search" @click="search">搜索</el-button>
      </el-form-item>
    </el-form>
    <!--列表-->
    <el-table size="small" :data="listData" highlight-current-row v-loading="loading" border
              element-loading-text="拼命加载中" style="width: 100%;">
      <el-table-column align="center" type="index" width="60">
      </el-table-column>
      <el-table-column sortable prop="orderNo" label="订单编号">
      </el-table-column>
      <el-table-column sortable prop="goods" label="下单商品" show-overflow-tooltip>
      </el-table-column>
      <el-table-column sortable prop="number" label="下单数量" show-overflow-tooltip>
      </el-table-column>
      <el-table-column sortable prop="user" label="下单用户" show-overflow-tooltip>
      </el-table-column>
      <el-table-column sortable prop="price" label="支付金额" show-overflow-tooltip>
      </el-table-column>
      <el-table-column sortable prop="orderDate" label="下单时间" show-overflow-tooltip>
      </el-table-column>
      <el-table-column sortable label="状态" show-overflow-tooltip>
        <template slot-scope="scope">
          <el-tag effect="dark" v-if="scope.row.status===0">已支付</el-tag>
          <el-tag type="success" effect="dark" v-if="scope.row.status===1">交易成功</el-tag>
          <el-tag type="danger" effect="dark" v-if="scope.row.status===2">交易失败</el-tag>
          <el-tag type="info" effect="dark" v-if="scope.row.status===3">退款进行中</el-tag>
          <el-tag type="success" effect="dark" v-if="scope.row.status===4">退款成功</el-tag>
          <el-tag type="danger" effect="dark" v-if="scope.row.status===5">退款失败</el-tag>
        </template>

      </el-table-column>
      <el-table-column align="center" label="操作" min-width="100">
        <template slot-scope="scope">
          <el-button size="mini" @click="order(scope.$index, scope.row)">确认</el-button>
          <el-button size="mini" type="danger" @click="refund(scope.$index, scope.row)">退款</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage"
      :page-sizes="[5,10,20]"
      :page-size="size"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>

  </div>
</template>

<script>
import Request from "../../api/request";

export default {
  data() {
    return {
      currentPage: 1,
      size: 5,
      total: 0,
      loading: false, //是显示加载
      editFormVisible: false, //控制编辑页面显示与隐藏
      title: '预览',

      payway: [
        {key: '已支付', value: 0},
        {key: '出货成功', value: 1},
        {key: '出货失败', value: 2},
        {key: '退款进行中', value: 3},
        {key: '退款成功', value: 4},
        {key: '退款失败', value: 5},
      ],/*   payway: [
        {key: '请选择', value: 0},
        {key: '初始化', value: 1},
        {key: '已支付', value: 2},
        {key: '出货成功', value: 3},
        {key: '出货失败', value: 4},
        {key: '订单超时', value: 5},
        {key: '退款初始化', value: 11},
        {key: '退款进行中', value: 12},
        {key: '退款成功', value: 13},
        {key: '退款失败', value: 14},
        {key: '订单处理中', value: 10}
      ],*/
      editForm: {
        id: '',
        name: '',
        payType: 1,
        partner: '',
        subMchId: '',
        appid: '',
        notifyUrl: '',
        signType: '',
        partnerKey: '',
        sellerUserId: '',
        certPath: '',
        certPassword: '',
        rsaKey: '',
        token: localStorage.getItem('logintoken')
      },
      formInline: {
        page: 1,
        limit: 10,
        machineNo: '',
        orderNo: '',
        transId: '',
        payType: 0,
        orderStatus: 0,
        token: localStorage.getItem('logintoken')
      },
      // 删除部门
      seletedata: {
        ids: '',
        token: localStorage.getItem('logintoken')
      },
      userparm: [], //搜索权限
      listData: [], //用户数据
      // 分页参数

    }
  },
  // 注册组件

  /**
   * 数据发生改变
   */

  /**
   * 创建完毕
   */
  mounted() {
    this.select()
  },

  /**
   * 里面的方法只有被调用才会执行
   */
  methods: {

    refund(index,row) {
      Request.post("order/refund", row).then(res => {

      })
    },
    order(index, row) {
      if (row.status === 0) {
        Request.post("order/order", row).then(res => {

          this.select()
        })
      }
    },
    // 获取公司列表
    handleSizeChange(val) {
      this.size = val
      this.select()
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.currentPage = val
      this.select()
    },

    select() {
      Request.get("/order?current=" + this.currentPage + "&size=" + this.size)
        .then(res => {
          this.loading = false
          // console.log(res)

          this.listData = res.data.data.records
          // 分页赋值
          this.currentPage = res.data.data.current
          this.size = res.data.data.size
          this.total = res.data.data.total

        })
    },
    // 分页插件事件
    callFather(parm) {
      this.pageparm.page = parm.currentPage
      this.pageparm.pageSize = parm.pageSize
      this.select()
      // this.getdata(this.formInline)
    },
    // 搜索事件
    search() {
      this.getdata(this.formInline)
    },
    //显示编辑界面

    // 编辑、增加页面保存方法
    submitForm(editData) {
      this.$refs[editData].validate(valid => {
        if (valid) {
          ConfigSave(this.editForm)
            .then(res => {
              this.editFormVisible = false
              this.loading = false
              if (res.success) {
                this.getdata(this.formInline)
                this.$message({
                  type: 'success',
                  message: '公司保存成功！'
                })
              } else {
                this.$message({
                  type: 'info',
                  message: res.msg
                })
              }
            })
            .catch(err => {
              this.editFormVisible = false
              this.loading = false
              this.$message.error('支付配置信息保存失败，请稍后再试！')
            })
        } else {
          return false
        }
      })
    },
    // 删除公司

    // 关闭编辑、增加弹出框
    closeDialog(formName) {
      this.editFormVisible = false
      this.$refs[formName].resetFields()
    }
  }
}
</script>

<style scoped>
.user-search {
  margin-top: 20px;
}

.userRole {
  width: 100%;
}
</style>




